package com.hisense.ovcloud.asop.routers;

import com.hisense.ovcloud.asop.dto.resp.ASOPBaseResp;
import com.hisense.ovcloud.asop.service.PairlogService;
import com.hisense.ovcloud.asop.service.PublicInfoService;
import com.hisense.ovcloud.asop.service.ServiceLogService;
import com.hisense.ovcloud.commons.configs.validator.BaseRouterConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.path;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;

@Configuration
public class RoutersConfiguration extends BaseRouterConfiguration {

    private final PairlogService pairlogService;

    private final PublicInfoService publicInfoService;

    private final ServiceLogService serviceLogService;

    public RoutersConfiguration(PairlogService pairlogService, PublicInfoService publicInfoService, ServiceLogService serviceLogService) {
        this.pairlogService = pairlogService;
        this.publicInfoService = publicInfoService;
        this.serviceLogService = serviceLogService;
    }

    @Bean
    public RouterFunction<ServerResponse> basicDataRoutes() {
        return RouterFunctions.nest(path("/aosp/v1"),
                route()
                        .POST("/getBindDevicesInfo", req -> ServerResponse.ok().body(publicInfoService.fetchBindDevicesInfo(req),
                                ASOPBaseResp.class))
                        .POST("/getBindDevicesUpgradeResult", req -> ServerResponse.ok().body(publicInfoService.fetchWifiUpgradeResults(req),
                                ASOPBaseResp.class))
                        .POST("/getBigdataBindRelations", req -> ServerResponse.ok().body(publicInfoService.fetchBindHistory(req),
                                ASOPBaseResp.class))


                        .POST("/fetchPairResult", req -> ServerResponse.ok().body(pairlogService.fetchPairResult(req),
                                ASOPBaseResp.class))
                        .POST("/fetchPairDetail", req -> ServerResponse.ok().body(pairlogService.fetchPairDetail(req),
                                ASOPBaseResp.class))

                        .POST("/fetchCDCAccountInfo", req -> ServerResponse.ok().body(pairlogService.fetchCDCAccountInfo(req),
                                ASOPBaseResp.class))
                        .POST("/fetchWifistatusByWifiId", req -> ServerResponse.ok().body(pairlogService.fetchWifistatusByWifiId(req),
                                ASOPBaseResp.class))
                        .POST("/queryJulinkLogs", req -> ServerResponse.ok().body(pairlogService.queryJulinkLogs(req),
                                ASOPBaseResp.class))
                        .POST("/queryMetricBizLog", req -> ServerResponse.ok().body(serviceLogService.queryMetricBizLog(req),
                                ASOPBaseResp.class))
                        .build());
    }
}

